import {getEnvPath} from '../utils';

if(!localStorage.getItem('domain')){
    localStorage.setItem('domain', 'http://cloud.jss.com.cn/')
}

if(!localStorage.getItem('website')){
    localStorage.setItem('website', 1)
}

const envPath = getEnvPath();

let users = JSON.parse(localStorage.getItem('users') || '[]');

users = users.filter(v => {
    return v.realname != '' && envPath === v.envPath
})

const defaultState = {
    users
}

export default function(state = defaultState, action){
    switch(action.type){
        case 'user/change':
            localStorage.setItem('users', JSON.stringify(action.data.users))
            return {...state, ...action.data}
        default:
            return state
    }
}